package com.wft.面试题;

import java.lang.reflect.Field;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class 颠倒数组 {
    public static void main(String[] args) throws Exception {
        Stream.of(1, 2, 3, 4, 5, 6, 7, 8).sorted((o1, o2) -> o2.compareTo(o1)).collect(Collectors.toList()).forEach(System.out::println);

        Integer a = 1, b = 2;
        System.out.println("a ==> " + a + " ==> b ==> " + b);
        swap(a, b);
        System.out.println("a ==> " + a + " ==> b ==> " + b);
    }

    public static void swap(Integer i1, Integer i2) throws Exception {
        Integer temp = new Integer(i1);
        Field field = Integer.class.getDeclaredField("value");
        field.setAccessible(true);
        field.set(i1, i2);
        field.set(i2, temp);
    }
}
